package cn.autoOffice.controller;
/*
 *功能说明：工资控制层
 *@author 皮永浪
 *@Date 2023/3/29 11:09
 */

import cn.autoOffice.bean.pojo.Salary;
import cn.autoOffice.bean.vo.Result;
import cn.autoOffice.service.SalaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("salary")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    //员工查询个人工资
    @PostMapping("findSalary/{employeeCode}/{pageNo}/{pageSize}")
    public Result<PageInfo<Salary>> findSalaryInfo(@PathVariable(value = "employeeCode",required = false) Integer employeeCode,
                                                   @PathVariable Integer pageNo,
                                                   @PathVariable Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<Salary> salaries = salaryService.findSalaryByEmployeeCode(employeeCode);
        PageInfo pageInfo = new PageInfo(salaries);
        System.out.println("====" + pageInfo.getTotal());
        return Result.success(pageInfo);
    }

    //财务人员增加员工工资信息
    @PostMapping("addSalary")
    @ResponseBody
    public String addSalary(@RequestBody Salary salary){
        boolean i = salaryService.addSalaryInfo(salary);
        if (i){
            return "0013:添加工资信息成功";
        }else {
            return "0014:添加工资信息失败";
        }
    }
}
